<%@page import="helpers.LanguageHelper"%>
<%@page import="java.util.TreeMap"%>
<%@page import="entities.User"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
ImagesService imagesService = ImagesServiceFactory.getImagesService();
User user = (User) request.getAttribute("user");
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
LanguageHelper translate = (LanguageHelper) request.getAttribute("translate");

%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp" />
            <div id="mainContent" class="left">
                <div id="editProfilePage">
                	<h3 class="title"><%=translate.getString("avatar_page") %></h3>
                	<% if (success != null) { %>
                	<div class="messageBox-success"><%=success %></div>
                	<% } %>
                	<% if (check != null && check.get("avatar") != null) { %>
                	<div class="messageBox-error"><%=check.get("avatar") %></div>
                	<% } %>
                    <div class="editProfile clearafter">
                    	<form method="post" class="formStyle" action="<%= blobstoreService.createUploadUrl("/profile/change-avatar") %>" enctype="multipart/form-data"> 
                            <div class="left authorAvatar">
                            	<% 
									if (user.getAvatar() != null && !user.getAvatar().isEmpty())  {
										 BlobKey blobKey = new BlobKey(user.getAvatar());
								%>
								<img alt="" src="<%=imagesService.getServingUrl(blobKey) %>=s120-c"><br />
								<% } else { %>							
								<img class="img-full-width" src="/images/icon-author.jpg" />
								<% } %>
                            </div>
                            <div>
                                <label><%=translate.getString("avatar_label") %> :</label> <input type="file" id="avatar_file" name="avatar" value="Upload" />
                            </div>
                            <div class="clearbreak"></div>
                            <button type="submit"><%=translate.getString("change_profile") %></button>
                            <input type="hidden" name="userid" value="<%=user.getId()%>">
                        </form>
                    </div>                    
                </div>
            </div>
            
            <jsp:include page="/elements/right.jsp" />
            
            <div class="clearbreak"></div>
<jsp:include page="/layouts/footer.jsp" />